<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '450px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          top: '0',
          data: ['客户报修抢修', '线路委托运维', '充电桩运维', '配电室运维', '电子化移交','高低压业扩', '临电共享服务', '带电作业服务', '配电设备销售', '电气设备预试']
        },
        series: [
          {
            name: '各业务占比',
            type: 'pie',
            // roseType: 'radius',
            radius: ['40%', '70%'],
            // center: ['50%', '38%'],
            avoidLabelOverlap: false,
            labelLine: {
              show: false
            },
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 24,
                fontWeight: 'bold'
              }
            },
            data: [
              { value: 320, name: '客户报修抢修' },
              { value: 240, name: '线路委托运维' },
              { value: 149, name: '充电桩运维' },
              { value: 100, name: '配电室运维' },
              { value: 59, name: '高低压业扩' },
              { value: 126, name: '带电作业服务' },
              { value: 126, name: '配电设备销售' },
              { value: 256, name: '电子化移交' },
              { value: 104, name: '临电共享服务' },
              { value: 311, name: '电气设备预试' },
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
    }
  }
}
</script>
